Trapping Rain Water
Hard
Question
Given a list of non-negative integers representing the heights of walls, calculate the total amount of water that can be trapped after a rainfall.
Input: walls = [4, 2, 0, 3, 2, 3, 1]
Output: 5
Input: walls = [3, 1, 5, 2, 4, 2, 1]
Output: 4
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Given the walls map [0, 1, 0, 2, 0, 1], how much water can be trapped after rain?
1 unit of water
2 units of water
3 units of water
4 units of water
Take a moment to understand the problem and think of your approach before you start coding.